<#include "${ftl_skin}/common/header.ftl">

</head>
<body class="white-bg">
<div class="row animated fadeInRight dialog-panel-body">
  <div class="col-sm-12">
    <div class="ibox float-e-margins">
      <!--<div class="ibox-title">
        <h5>部门选择</h5>
        <div class="ibox-tools"> <a href="#" class="open-all"> <i class="fa fa-plus">全部展开</i> </a> <a href="#" class="close-all"> <i class="fa fa-minus">全部收起</i> </a> </div>
      </div>-->
      <div class="ibox-content p-r-none p-l-none p-t-none p-b-none">
        <div id="treeview1" class="test"></div>
      </div>
    </div>
  </div>
</div>
<#include "${ftl_skin}/common/js.ftl">
<script src="${path.skinPath }js/demo/layer-demo.min.js"></script> 
<script src="${path.skinPath }js/plugins/treeview/bootstrap-treeview.js"></script> 
<script src="${path.skinPath }js/plugins/sweetalert/sweetalert.min.js"></script> 
<script>
	$(function() {
        //调整body高度
   		initDialogPanel();
		
		var treeData = getTreeData();
		$("#treeview1").treeview({
			data: treeData,
			showTags: !0,
			showBottons: !1,
			onNodeClickFun:tree_click
		});
		$(".open-all").click(function () {
			$("#treeview1").treeview({
				data: treeData,
				levels: 99,
				showTags: !0,
				showBottons: !0
			});
		});
			
		$(".close-all").click(function () {
			$("#treeview1").treeview({
				data: treeData,
				levels: 1,
				showTags: !0,
				showBottons: !0
			});
		});
	});
	
	function getTreeData(){
		var treeList,treeData;
		$.ajax({
            url: "${path.servicePath}/dept/treelistauth.do",
            async: false,
            type: 'POST',
            data: {},
            success: function(data){
                if(data.state == 0){
                   treeList = data.result;
                }
            }
        });
		
		
		if(treeList.length>0){
			treeData = toTree(treeList,"-1");
		}
		
		return treeData;
	}
	
	function tree_botton_bind(){
	
		$("#treeview1 .tree-btn.check").click(function () {
			var tree_code = $(this).parents("li").attr("data-treeid");
			var node_name =$(this).parents("li").data("nodeInfo").node_name;
			var nodeId = $(this).parents("li").data("nodeInfo").id;
			var returnVal={
				nodeId:nodeId,
				nodeTreeCode:tree_code,
				nodeName:node_name
			};
			
			closeDialog(returnVal);
    	});
		
	}
	
	function tree_click(node){
		if(node){
			var tree_code = node.tree_code;
			var node_name =node.node_name;
			var nodeId = node.id;
			var returnVal={
				nodeId:nodeId,
				nodeTreeCode:tree_code,
				nodeName:node_name
			};
			
			closeDialog(returnVal);
		}else{
			alert("获取节点信息错误！");
		}
		
	}
	
	
	//=================================== list 转　树结构　==================================
	function toTree(data, pid) {
		var result = [], temp;
		for (var i = 0; i < data.length; i++) {
			if (data[i].parent_tree_code == pid) {
				var obj = data[i];
				obj.id = data[i].id;
				obj.text = data[i].node_name;
				temp = toTree(data, data[i].tree_code);
				if (temp.length > 0) {
					obj.nodes = temp;
				}
				
				result.push(obj);
			}
		}
		
		return result;
	}
	
</script> 
<#include "${ftl_skin}/common/footer.ftl"> 